﻿/*************************************************************************
 *  Copyright © 2023-2030 Administrator. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：DefaultCompany
 *  项目：CustomBuildProcess
 *  文件：PathManager.cs
 *  作者：Administrator
 *  日期：2024/11/20 22:10:41
 *  功能：Nothing
*************************************************************************/

using System.IO;
using System.Reflection;
using UnityEditor.Build.Reporting;
using UnityEngine;

namespace CustomBuildProcess.Editor
{
    public static class PathManager
    {

        public static string BuildDataPath
        {
            get
            {
                return Path.Combine("Assets", "CustomBuildProcessData");
            }
        }

        public static string BuildLogHtmlPath
        {
            get
            {
                return Path.Combine(BuildDataPath, "build_log.html");
            }
        }

        public static string BuildLogHtmlTemplatePath
        {
            get
            {
                string iconPath = Path.Combine(PackagePath, $"Editor/Resources/build_log_template.html");

                iconPath = iconPath.Replace('\\', '/');

                return iconPath;
            }
        }

        public static string BuildLogHtmlEncryptTemplatePath
        {
            get
            {
                string iconPath = Path.Combine(PackagePath, $"Editor/Resources/build_log_encrypt_template.html");

                iconPath = iconPath.Replace('\\', '/');

                return iconPath;
            }
        }

        public static string LogItemHtmlTemplatePath
        {
            get
            {
                string iconPath = Path.Combine(PackagePath, $"Editor/Resources/log_template.html");

                iconPath = iconPath.Replace('\\', '/');

                return iconPath;
            }
        }


        /// <summary>
        /// 获取打包设置配置文件路径
        /// </summary>
        public static string BuildConfigPath
        {
            get
            {
                return Path.Combine(BuildDataPath, "BuildSettingConfig.asset");
            }
        }

        public static string BuildConfigItemPath
        {
            get
            {
                return "BuildConfigItem";
            }
        }


        public static string PresetIconPath()
        {
            var iconPath = PackagePath;

            iconPath = Path.Combine(iconPath, $"Editor/PresetIcons");

            iconPath = iconPath.Replace('\\', '/');

            return iconPath;
        }


        public static string IconPath(string iconName)
        {
            var iconPath = PresetIconPath();

            iconPath = Path.Combine(iconPath, $"{iconName}");

            iconPath = iconPath.Replace('\\', '/');

            return iconPath;
        }

        public static string BuildOutputHtmlLogPath(BuildReport report)
        {
            string buildOutputPath = report.summary.outputPath;

            buildOutputPath = Path.GetDirectoryName(buildOutputPath);

            // 目标打包路径下的日志文件路径
            string targetLogPath = Path.Combine(buildOutputPath, "software_info.xml");

            return targetLogPath;
        }

        /// <summary>
        /// 包相对路径
        /// </summary>

        public static string PackagePath
        {
            get
            {
                var assembly = Assembly.GetExecutingAssembly();
                var pInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(assembly);

                if (pInfo == null)
                    return null;

                return pInfo.assetPath.Replace('\\', '/');
            }
        }
    }
}

